<template>
  <div class="home-page">
    <!-- 页面标题 -->
    <div class="page-header">
      <h1>欢迎来到管理系统</h1>
      <p class="sub-title">这是您的个人数据看板</p>
    </div>

    <!-- 数据概览卡片 -->
    <div class="stats-container">
      <div class="stat-card card-visit">
        <div class="stat-icon">📊</div>
        <div class="stat-info">
          <div class="stat-value">1,234</div>
          <div class="stat-label">总访问量</div>
          <div class="stat-trend positive"><i class="trend-icon"></i> 12.5%</div>
        </div>
      </div>
      <div class="stat-card card-user">
        <div class="stat-icon">👥</div>
        <div class="stat-info">
          <div class="stat-value">567</div>
          <div class="stat-label">活跃用户</div>
          <div class="stat-trend positive"><i class="trend-icon"></i> 8.2%</div>
        </div>
      </div>
      <div class="stat-card card-task">
        <div class="stat-icon">✅</div>
        <div class="stat-info">
          <div class="stat-value">89%</div>
          <div class="stat-label">任务完成率</div>
          <div class="stat-trend positive"><i class="trend-icon"></i> 3.1%</div>
        </div>
      </div>
      <div class="stat-card card-message">
        <div class="stat-icon">💬</div>
        <div class="stat-info">
          <div class="stat-value">24</div>
          <div class="stat-label">未读消息</div>
          <div class="stat-trend negative"><i class="trend-icon"></i> 2.7%</div>
        </div>
      </div>
    </div>

    <!-- 图表区域 -->
    <div class="charts-container">
      <div class="chart-card">
        <div class="chart-header">
          <h3>最近7天访问量</h3>
          <div class="chart-filter">
            <button class="filter-btn active">周</button>
            <button class="filter-btn">月</button>
            <button class="filter-btn">年</button>
          </div>
        </div>
        <div class="chart-placeholder">
          <div class="bar-chart">
            <div class="bar-item">
              <div class="bar" style="height: 60%"></div>
              <div class="bar-label">周一</div>
            </div>
            <div class="bar-item">
              <div class="bar" style="height: 45%"></div>
              <div class="bar-label">周二</div>
            </div>
            <div class="bar-item">
              <div class="bar" style="height: 70%"></div>
              <div class="bar-label">周三</div>
            </div>
            <div class="bar-item">
              <div class="bar" style="height: 55%"></div>
              <div class="bar-label">周四</div>
            </div>
            <div class="bar-item">
              <div class="bar" style="height: 80%"></div>
              <div class="bar-label">周五</div>
            </div>
            <div class="bar-item">
              <div class="bar" style="height: 65%"></div>
              <div class="bar-label">周六</div>
            </div>
            <div class="bar-item">
              <div class="bar" style="height: 90%"></div>
              <div class="bar-label">周日</div>
            </div>
          </div>
        </div>
      </div>

      <div class="chart-card">
        <div class="chart-header">
          <h3>任务完成进度</h3>
          <div class="chart-filter">
            <button class="filter-btn active">本周</button>
            <button class="filter-btn">本月</button>
          </div>
        </div>
        <div class="chart-placeholder">
          <div class="pie-chart-container">
            <div class="pie-chart">
              <div class="pie-progress" style="--progress: 89%">
                <div class="pie-animation"></div>
              </div>
              <div class="pie-text">89%</div>
            </div>
            <div class="pie-legend">
              <div class="legend-item">
                <div class="legend-color"></div>
                <div class="legend-text">已完成</div>
              </div>
              <div class="legend-item">
                <div class="legend-color remaining"></div>
                <div class="legend-text">未完成</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 最近活动 -->
    <div class="activities-container">
      <div class="activities-header">
        <h3>最近活动</h3>
        <button class="view-all-btn">查看全部</button>
      </div>
      <div class="activity-list">
        <div class="activity-item">
          <div class="activity-icon completed"></div>
          <div class="activity-content">
            <div class="activity-time">今天 09:30</div>
            <div class="activity-desc">用户 <span class="highlight">张三</span> 完成了任务 <span class="highlight">网站首页设计</span>
            </div>
          </div>
        </div>
        <div class="activity-item">
          <div class="activity-icon system"></div>
          <div class="activity-content">
            <div class="activity-time">今天 08:15</div>
            <div class="activity-desc">系统更新了 <span class="highlight">安全补丁</span></div>
          </div>
        </div>
        <div class="activity-item">
          <div class="activity-icon created"></div>
          <div class="activity-content">
            <div class="activity-time">昨天 17:45</div>
            <div class="activity-desc">用户 <span class="highlight">李四</span> 创建了新任务 <span class="highlight">移动端适配</span>
            </div>
          </div>
        </div>
        <div class="activity-item">
          <div class="activity-icon released"></div>
          <div class="activity-content">
            <div class="activity-time">昨天 14:20</div>
            <div class="activity-desc">项目 <span class="highlight">v2.1.0</span> 版本发布</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
// 这里可以添加组件逻辑
// 例如从API获取数据
import { ref, onMounted } from 'vue'
// import { fetchDashboardData } from '@/api/dashboard'

const stats = ref({})
const activities = ref([])
const chartData = ref([])

onMounted(async () => {
  // 模拟数据加载效果
  setTimeout(() => {
    // 添加卡片动画
    const cards = document.querySelectorAll('.stat-card')
    cards.forEach((card, index) => {
      setTimeout(() => {
        card.classList.add('animated')
      }, 100 * index)
    })

    // 添加图表动画
    const bars = document.querySelectorAll('.bar')
    bars.forEach((bar, index) => {
      setTimeout(() => {
        bar.style.height = bar.style.height
      }, 300 + 100 * index)
    })
  }, 300)

  try {
    // const data = await fetchDashboardData()
    // stats.value = data.stats
    // activities.value = data.activities
    // chartData.value = data.chartData
  } catch (error) {
    console.error('Failed to fetch dashboard data:', error)
  }
})
</script>

<style lang="scss" scoped>
@use '@/assets/styles/variables.module.scss' as vars;

/* 基础样式 */
.home-page {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* 页面标题 */
.page-header {
  margin-bottom: 32px;
  animation: fadeIn 0.5s ease;
}

.page-header h1 {
  font-size: 28px;
  color: var(--font-color);
  margin-bottom: 8px;
  font-weight: 600;
}

.sub-title {
  color: var(--font-sub-color);
  font-size: 16px;
}

/* 数据卡片容器 */
.stats-container {
  display: flex;
  gap: 24px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

/* 数据卡片 */
.stat-card {
  flex: 1;
  min-width: 220px;
  background: var(--card-bg);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 16px rgba(var(--card-bg), 0.2);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.3s ease;
  transform: translateY(20px);
  opacity: 0;
}

.stat-card.animated {
  transform: translateY(0);
  opacity: 1;
}

.stat-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* 不同卡片主题色 */
.card-visit .stat-icon {
  background-color: #e6f7ff;
  color: #1890ff;
}

.card-user .stat-icon {
  background-color: #fff2e8;
  color: #fa8c16;
}

.card-task .stat-icon {
  background-color: #e6fffb;
  color: #00b42a;
}

.card-message .stat-icon {
  background-color: #f9f0ff;
  color: #722ed1;
}

/* 卡片图标 */
.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 24px;
}

/* 卡片信息 */
.stat-info {
  flex: 1;
}

.stat-value {
  font-size: 26px;
  font-weight: 600;
  color: var(--font-color);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 14px;
  color: var(--font-sub-color);
  margin-bottom: 4px;
}

/* 趋势指标 */
.stat-trend {
  font-size: 12px;
  display: flex;
  align-items: center;
}

.positive {
  color: #00b42a;
}

.negative {
  color: #f53f3f;
}

.trend-icon {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.positive .trend-icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2300b42a'%3E%3Cpath d='M12 2L4 8l1.4 1.4L12 5.2l6.6 4.2L20 8l-8-6z'/%3E%3C/svg%3E");
}

.negative .trend-icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23f53f3f'%3E%3Cpath d='M12 22L4 16l1.4-1.4L12 18.8l6.6-4.2L20 16l-8 6z'/%3E%3C/svg%3E");
}

/* 图表容器 */
.charts-container {
  display: flex;
  gap: 24px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

/* 图表卡片 */
.chart-card {
  flex: 1;
  min-width: 300px;
  background: var(--card-bg);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.chart-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* 图表标题栏 */
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.chart-header h3 {
  font-size: 18px;
  color: var(--font-color);
  font-weight: 600;
}

/* 图表筛选按钮 */
.chart-filter {
  display: flex;
  gap: 8px;
}

.filter-btn {
  padding: 6px 12px;
  border-radius: 6px;
  background-color: #f7f8fa;
  color: #4e5969;
  border: none;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-btn:hover {
  background-color: #e5e6eb;
}

.filter-btn.active {
  background-color: #e6f7ff;
  color: #1890ff;
}

/* 图表占位区 */
.chart-placeholder {
  height: 240px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

/* 柱状图 */
.bar-chart {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  gap: 12px;
  padding-bottom: 30px;
}

.bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 40px;
  height: 100%;
  justify-content: flex-end;
}

.bar {
  width: 100%;
  background-color: #4096ff;
  border-radius: 6px 6px 0 0;
  transition: height 1s ease;
  height: 0;
  background-image: linear-gradient(to top, #4096ff, #73c0fc);
  position: relative;
  overflow: hidden;
}

.bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.2);
  animation: shimmer 2s infinite;
  transform: skewX(-20deg);
}

.bar-label {
  margin-top: 8px;
  font-size: 12px;
  color: var(--font-sub-color);
}

/* 饼图容器 */
.pie-chart-container {
  display: flex;
  align-items: center;
  gap: 30px;
}

/* 饼图 */
.pie-chart {
  width: 180px;
  height: 180px;
  position: relative;
}

.pie-progress {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: conic-gradient(#4096ff var(--progress),
      var(--theme-border) 0);
  position: relative;
  transition: all 1s ease;
}

.pie-animation {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: linear-gradient(90deg, transparent 50%, rgba(255, 255, 255, 0.2) 50%);
  animation: rotate 3s linear infinite;
}

.pie-progress::after {
  content: '';
  position: absolute;
  width: 70%;
  height: 70%;
  /* background-color: #F2F6FC; */
  background: var(--card-bg);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.pie-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 28px;
  font-weight: 600;
  color: #1d2129;
  z-index: 1;
}

/* 饼图图例 */
.pie-legend {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background-color: #4096ff;
}

.legend-color.remaining {
  background-color: #d4d7de;
}

.legend-text {
  font-size: 14px;
  color: #4e5969;
}

/* 活动容器 */
.activities-container {
  /* background-color: #F2F6FC; */
  background: var(--card-bg);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
}

.activities-container:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* 活动标题栏 */
.activities-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.activities-header h3 {
  font-size: 18px;
  color: var(--font-color);
  font-weight: 600;
}

/* 查看全部按钮 */
.view-all-btn {
  padding: 6px 12px;
  border-radius: 6px;
  background-color: transparent;
  color: #4096ff;
  border: 1px solid #4096ff;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.view-all-btn:hover {
  background-color: #e6f7ff;
}

/* 活动列表 */
.activity-list {
  max-height: 320px;
  overflow-y: auto;
}

/* 活动项 */
.activity-item {
  padding: 16px 10px;
  border-bottom: 1px solid var(--theme-border);
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: background-color 0.2s ease;
}

.activity-item:hover {
  background-color: var(--card-hover-bg);
}

.activity-item:last-child {
  border-bottom: none;
}

/* 活动图标 */
.activity-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background-color: #e6f7ff;
  margin-top: 2px;
  position: relative;
}

.activity-icon::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.activity-icon.completed::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%231890ff'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E");
}

.activity-icon.system::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23fa8c16'%3E%3Cpath d='M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-7 14h-2v-4H8v-2h2V9h2v2h2v2h-2v4z'/%3E%3C/svg%3E");
}

.activity-icon.created::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2300b42a'%3E%3Cpath d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/%3E%3C/svg%3E");
}

.activity-icon.released::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23722ed1'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z'/%3E%3C/svg%3E");
}

/* 活动内容 */
.activity-content {
  flex: 1;
}

.activity-time {
  font-size: 12px;
  color: #86909c;
  margin-bottom: 4px;
}

.activity-desc {
  font-size: 14px;
  color: var(--font-sub-color);
  line-height: 1.5;
}

.highlight {
  color: #4096ff;
  font-weight: 500;
}

/* 动画效果 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%) skewX(-20deg);
  }

  100% {
    transform: translateX(100%) skewX(-20deg);
  }
}

@keyframes rotate {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* 响应式调整 */
@media (max-width: 768px) {
  .stats-container {
    flex-direction: column;
  }

  .stat-card {
    min-width: 100%;
  }

  .charts-container {
    flex-direction: column;
  }

  .chart-card {
    min-width: 100%;
  }

  .pie-chart-container {
    flex-direction: column;
  }
}
</style>